<!DOCTYPE html>
<html lang="en">
<head>
    <title>一般缴款书电子票</title>
    <#include "../inc/header.ftl"/>
    <link rel="stylesheet" href="${prefix}/assets/custom/css/main.css?20240428"/>
</head>

<body class="no-skin">

<div class="main-container ace-save-state" id="main-container">

    <div class="main-content">
        <div class="main-content-inner">

            <div class="page-content">
                <table width="900" border="0" align="center" cellpadding="0" cellspacing="0" class="r_tablebr">
                    <tr>
                        <td class="r_nr">
                            <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td class="r_title">河北省非税收入一般缴款书</td>
                                </tr>
                            </table>
                            <form name="ChargeBillForm" id="ChargeBillForm" action="queryChargeBillData" method="post">
                                <input name="filldate" type="hidden" id="filldate" value=""/>
                                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <tr>
                                        <td width="35%">执收单位编码：
                                            <input name="unitcode" type="text" id="unitcode" readonly="readonly" value="" class="r_input" />          <label for="textfield"></label></td>
                                        <td align="right" colspan="3">缴款码：<input name="billnum" type="text" id="billnum" value="" class="r_input2" style="width:100px;" />
                                            &emsp;交易流水号：<input type="text" id="bankaffirm" name="bankaffirm" value="" class="r_input2" style="width:170px;"></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">执收单位名称：
                                            <input name="unitname" type="text" id="unitname" readonly="readonly" style="width:230px" value="" class="r_input" /></td>
                                        <td width="20%" align="center" class="r_zsdwbmwz">开票日期：<span id="filldateshow">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
                                        <td width="20%" align="left" class="r_zsdwbmwz">过期日期：<span id="guoqidateshow">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx2">
                                    <tr>
                                        <td width="15%" align="right">付款人全称</td>
                                        <td width="35%"><input name="payer" type="text" id="payer" readonly="readonly" style="width:95%" value="" /></td>
                                        <td width="15%" align="right">收款人全称</td>
                                        <td width="35%"><input name="payee" type="text" id="payee" readonly="readonly" style="width:95%" value="" /></td>
                                    </tr>
                                    <tr>
                                        <td align="right">付款人账号</td>
                                        <td><input type="text" name="payeraccount" id="payeraccount" readonly="readonly" value="" style="width:95%" /></td>
                                        <td width="15%" align="right">收款人账号</td>
                                        <td><input name="payeeaccount" type="text" id="payeeaccount" readonly="readonly" style="width:95%" value="" /></td>
                                    </tr>
                                    <tr>
                                        <td align="right">付款人开户银行</td>
                                        <td><input type="text" name="payerbank" id="payerbank" value="" readonly="readonly" style="width:95%" /></td>
                                        <td width="15%" align="right">收款人开户银行</td>
                                        <td><input name="payeebank" type="text" id="payeebank" style="width:95%" readonly="readonly" value="" /></td>
                                    </tr>
                                </table>
                                <table width="99%" border="1" cellpadding="0" cellspacing="1" class="r_jcxx" id="tab">
                                    <tr>
                                        <td width="10%" align="center">编码</td>
                                        <td width="40%" align="center">收入项目</td>
                                        <td width="10%" align="center">数量</td>
                                        <td width="20%" align="center">收缴标准</td>
                                        <td width="10%" align="center">金额</td>
                                    </tr>
                                    <tr id="tab-tr1">
                                        <td align="right">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="15%" align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr id="tab-tr2">
                                        <td align="right">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                    <tr id="tab-tr3">
                                        <td align="right">&nbsp;</td>
                                        <td>&nbsp;</td>
                                        <td width="15%" align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                        <td align="center">&nbsp;</td>
                                    </tr>
                                </table>
                                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="r_zsdwbm">
                                    <tr>
                                        <td width="20%">校验码：
                                            <input name="vertifycode" type="hidden" id="vertifycode" class="r_input2" style="width:60px" value="" />
                                            <input name="vertifycodeshow" type="text" id="vertifycodeshow" class="r_input2" style="width:60px" value="" />
                                        </td>
                                        <td width="20%">付款方式：
                                            <input name="paywaycode" type="text" id="paywaycode" class="r_input2" style="width:80px"/>
                                           </td>
                                        <td width="60%" align="right">金额（大写）：
                                            <input name="bigoriginfund" type="text" id="bigoriginfund" readonly="readonly" class="r_input" style="width:35%" value="" />
                                            （小写）：
                                            <input name="originfund" type="text" id="originfund" readonly="readonly" class="r_input" style="width:15%" value="" /></td>
                                    </tr>
                                </table>
                            </form>
                            <table width="99%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td height="40" align="right">
                                        <input type="button" name="button" id="button" class="r_button" onclick="queryChargeBillData()" value="查询单据" />
                                        <input type="button" name="paybutton" id="paybutton"  class="r_button" onclick="pay()" value="收款" />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </div><!-- /.page-content -->

        </div>
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->
<#include "../inc/basicjs.ftl"/>
<script src="${prefix}/assets/custom/js/commonview.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    var ischeck = false;
    jQuery(function($) {
        //缴款方式下拉框
        $('#paywaycode').combobox({
            data: _paywaydata,
            valueField:'paywayid',
            textField:'paywayname',
            panelHeight:'auto',
            onLoadSuccess:function(){
                var data = $('#paywaycode').combobox('getData');//获取所有下拉框数据
                if (data.length > 0) {
                    //如果有数据的话默认选中第一条数据
                    $('#paywaycode').combobox('select',data[0].paywayid);
                }
            }
        });
    })
    //数据初始化
    function pay(){
        if(!ischeck) {
            $.messager.alert('提示', "请先输入缴费编码，然后查询单据后再点击收款！", 'info');
            $("#billnum").focus();
            ischeck = false;
            return;
        }
        if($("#bankaffirm").val()=="") {
            $.messager.alert('提示', '请填写交易流水号！', 'info');
            return false;
        }
        var vertifycode = $("#vertifycode").val();
        var vertifycodeshow = $("#vertifycodeshow").val();
        if(vertifycode != vertifycodeshow || vertifycodeshow.length!=4){
            $.messager.alert('提示', '校验码输入错误，请重新输入！', 'info');
            return;
        }else{
            $('#paybutton').attr('disabled',"true");//添加disabled属性
            $('#ChargeBillForm').form({
                url: prefix + '/view/chargebill/chargebillpay',
                onSubmit:function(){
                    var isValid = $(this).form('validate');
                    if (isValid){
                        $.messager.progress({
                            title: '提示',
                            msg: '数据处理中，请稍候……',
                            text: ''
                        });
                    }
                    return isValid;
                },
                success:function(data) {
                    $.messager.progress('close');
                    var data = eval('(' + data + ')');
                    if (data.success) {
                        ischeck = false;
                        $.messager.alert('提示', data.msg, 'info', function() {
                            location=prefix+'/view/chargebill/chargebillview';
                        });
                    } else {
                        $('#paybutton').removeAttr("disabled");// 移除disabled属性
                        $.messager.alert('提示', "【" + data.code + "】" + data.msg, 'info');
                    }
                }
            });
            $('#ChargeBillForm').submit();
        }
    }


    function queryChargeBillData() {
        var state = [{"key":"0","value":"未知错误"},{"key":"1","value":"正常"},{"key":"2","value":"账户类型不符"},{"key":"3","value":"已收款"},{"key":"4","value":"票据不存在"},{"key":"5","value":"对账不成功，账户停用"},{"key":"6","value":"验签未通过"},{"key":"7","value":"该票据已超期"}];
        var billnum = $("#billnum").val();
        if(billnum=="") {
            $.messager.alert('提示', '请输入缴款码！', 'info');
            $("#billnum").focus();
            return;
        }
        $.messager.progress({
            title: '提示',
            msg: '正在获取票据，请稍候……',
            text: ''
        });
        $.ajax({
            type: "POST",
            url: prefix+'/view/chargebill/queryChargeBillData',
            dataType: 'json',
            data: { billnum: billnum},
            success: function (dataOne) {
                $.messager.progress('close');
                if (!dataOne.success) {
                    $.messager.alert('提示', dataOne.msg, 'info');
                    return;
                }
                var bill = dataOne.data;
                if (bill.billstate == 3 || bill.billstate == 1) {
                    $("#billnum").val(bill.billnum);
                    $("#unitcode").val(bill.unitcode);
                    $("#unitname").val(bill.unitname);
                    $("#payer").val(bill.payer);
                    $("#payee").val(bill.payee);
                    $("#payeraccount").val(bill.payeraccount);
                    $("#payeeaccount").val(bill.payeeaccount);
                    $("#payerbank").val(bill.payerbank);
                    $("#payeebank").val(bill.payeebank);
                    $("#backbillnum").val(bill.backbillnum);
                    $("#vertifycode").val(bill.vertifycode);
                    var filldate = bill.filldate;
                    $("#filldate").val(filldate);
                    $("#filldateshow").html(filldate);
                    $("#guoqidateshow").html(dateCount(filldate,10));

                    var details_length = bill.detailVOS.length;
                    if(details_length>0){
                        $("#tab-tr1").remove();
                        $("#tab-tr2").remove();
                        $("#tab-tr3").remove();
                        var rownum = 0;
                        var $tr = $("#tab tr:last");
                        var strhtml = "";
                        var bigoriginfund = "0.00";
                        for (var i=0;i<bill.detailVOS.length;i++) {
                            var d = bill.detailVOS[i];
                            var itemcode = d.itemcode;
                            var itemname = d.itemname;
                            var amount = d.amount;
                            var cityscale = d.cityscale;
                            var originfund = (parseFloat(d.originfund)).toFixed(2);
                            strhtml = '<tr id="tab-tr'+(rownum+1)+'"><td align="center">'+itemcode+'</td><td>'+itemname+'</td><td width="15%" align="center">'+amount+'</td><td align="center">'+cityscale+'</td><td align="center">'+originfund+'</td></tr>';
                            $tr.after(strhtml);
                            bigoriginfund = (parseFloat(bigoriginfund)+parseFloat(originfund)).toFixed(2);
                            rownum++;
                            $tr = $("#tab tr:last");
                        }
                        $("#originfund").val(bigoriginfund);
                        $("#bigoriginfund").val(upDigit(bigoriginfund));
                        while(rownum<3)
                        {
                            strhtml = '<tr id="tab-tr'+(rownum+1)+'"><td align="center">&nbsp;</td><td>&nbsp;</td><td width="15%" align="center">&nbsp;</td><td align="center">&nbsp;</td><td align="center">&nbsp;</td></tr>';
                            $tr.after(strhtml);
                            rownum++;
                            $tr = $("#tab tr:last")
                        }
                    }
                }
                if (bill.billstate == 1) {
                    $('#paybutton').attr('disabled',false);
                    $('#billnum').attr("readonly","readonly");
                    ischeck = true;
                } else {
                    $('#paybutton').attr('disabled',true);
                    $.messager.alert('提示', dataOne.msgExt, 'info');
                } 
            }
        })
    }
</script>
</body>
</html>
